<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改论文')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-paper-edit" th:object="${sciPaperA}">
            <input name="id" id="p_id" th:field="*{id}" type="hidden">

            <div class="form-group">    
                <label class="col-sm-3 control-label">论文名称：</label>
                <div class="col-sm-8">
                    <input name="paperTitle" th:field="*{paperTitle}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">论文类别：</label>
                <div class="col-sm-8">
                    <select name="topType" class="form-control" th:with="type=${@dict.getType('sci_paper_k')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{paperCategory}"></option>
                    </select>
                    <!--<input name="paperCategory" th:field="*{paperCategory}" class="form-control" type="text">-->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发表期刊：</label>
                <div class="col-sm-8">
                    <input name="publishedJournal" th:field="*{publishedJournal}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发表时间：</label>
                <div class="input-group date">
                    <input autocomplete="off" name="publicationTime" th:field="*{publicationTime}"
                           th:value="${#dates.format(publicationTime, 'yyyy-MM-dd')}"  class="form-control"
                           placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否与行业联合发表：</label>

                <div class="col-sm-9" >
                    <label class="radio-box">
                        <input name="isIndustryCollaborative" th:field="*{isIndustryCollaborative}" class="form-control" type="radio" value="是">是</label>
                    <label class="radio-box">
                        <input name="isIndustryCollaborative" th:field="*{isIndustryCollaborative}" class="form-control" type="radio" value="否">否</label>
                </div>

<!--                <div class="col-sm-8">-->
<!--                    <input name="isIndustryCollaborative" th:field="*{isIndustryCollaborative}" class="form-control" type="text">-->
<!--                </div>-->

            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否与地方联合发表：</label>
                <div class="col-sm-9" >
                    <label class="radio-box">
                        <input name="isLocalCollaborative" th:field="*{isLocalCollaborative}" class="form-control" type="radio" value="是">是</label>
                    <label class="radio-box">
                        <input name="isLocalCollaborative" th:field="*{isLocalCollaborative}"class="form-control" type="radio" value="否">否</label>
                </div>
<!--                <div class="col-sm-8">-->
<!--                    <input name="isLocalCollaborative" th:field="*{isLocalCollaborative}" class="form-control" type="text">-->
<!--                </div>-->

            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否与国际联合发表：</label>
                <div class="col-sm-9" >
                    <label class="radio-box">
                        <input name="isInternationalCollaborative" th:field="*{isInternationalCollaborative}" class="form-control" type="radio" value="是">是</label>
                    <label class="radio-box">
                        <input name="isInternationalCollaborative" th:field="*{isInternationalCollaborative}"class="form-control" type="radio" value="否">否</label>
                </div>
<!--                <div class="col-sm-8">-->
<!--                    <input name="isInternationalCollaborative" th:field="*{isInternationalCollaborative}" class="form-control" type="text">-->
<!--                </div>-->
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否是跨学科论文：</label>
                <div class="col-sm-9" >
                    <label class="radio-box">
                        <input name="isCrossDiscipline" th:field="*{isCrossDiscipline}" class="form-control" type="radio" value="是">是</label>
                    <label class="radio-box">
                        <input name="isCrossDiscipline" th:field="*{isCrossDiscipline}"class="form-control" type="radio" value="否">否</label>
                </div>
<!--                <div class="col-sm-8">-->
<!--                    <input name="isCrossDiscipline" th:field="*{isCrossDiscipline}" class="form-control" type="text">-->
<!--                </div>-->
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">排名：</label>
                    <div class="col-sm-8" th:with="type=${@dict.getType('sci_paper_qwer')}">
                        <select th:field="*{paperRanking}" disabled class="form-control m-b">
                            <!-- 默认选项 -->
                            <option value="" th:if="${#lists.isEmpty(type)}">无可用选项</option>
                            <!-- 动态生成选项 -->
                            <option th:each="dict : ${type}"
                                    th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"
                                    th:selected="${sciPaperA.paperRanking == dict.dictValue}">
                            </option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">论文网址：</label>
                <div class="col-sm-8">
                    <input name="search_web" th:field="*{search_web}"class="form-control" type="text">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">论文文件：</label>
                    <div class="col-sm-8">
                        <input th:field="*{text_paper}" hidden id="text_paper" type="text">
                        <div style="display: inline-block;">
                            <div id="contractFileName" style="display: inline; margin-right: 5px;"></div>
                        </div>
                        <div>
                            <button onclick="chakanpaper()" class="btn btn-sm btn-primary color">预览</button>
                            <button onclick="downloadFile('text_paper')" class="btn btn-sm btn-primary color">下载</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">论文word文件：</label>
                    <div class="col-sm-8">
                        <input th:field="*{word_paper}" hidden id="word_paper" type="text">
                        <div style="display: inline-block;">
                            <div id="wordFileName" style="display: inline; margin-right: 5px;"></div>
                        </div>
                        <div>
                            <button onclick="downloadFile('word_paper')" class="btn btn-sm btn-primary color">下载</button>
                        </div>
                    </div>
                </div>
            </div>

<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">科研分：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="researchScore" th:field="*{researchScore}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remarks" th:field="*{remarks}" class="form-control" type="text">
                </div>
            </div>

            <h4 class="form-header h4 tdiv2"  style="display:none;">退回记录</h4>
            <div class="row tdiv2" style="display:none;">
                <div class="col-sm-12">

                    <div class="form-group"  >
                        <table id='bootstrap-table'></table>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">

        function displayFileName(inputId, fileNameId) {
            const input = document.getElementById(inputId);
            const fileNameSpan = document.getElementById(fileNameId);
            if (input.value) {
                const fileName = input.value.split('/').pop(); // 获取文件名
                const parts = fileName.split('_'); // 按下划线分割
                const firstPart = parts[0]; // 下划线前的部分

                const dotParts = fileName.split('.'); // 按点分割
                const lastPart = dotParts[dotParts.length - 1]; // 点后的部分
                const year =0;
                fileNameSpan.textContent = `${firstPart}.${lastPart}`; // 组合并显示
            } else {
                fileNameSpan.textContent = '';
            }
        }
        function downloadFile(type){
            var c = $("#"+type).val();
            if(c){
                var a = document.createElement("a");
                a.href=c;
                a.download="";
                a.style.display = "none";
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            }else{
                alert("网址无效");
            }
        }

        function chakanpaper(){
            var c = $("#text_paper").val();
            console.log("c:",c)
            $.modal.openTab("查看论文文件" ,c);
        }



        var prefix = ctx + "system/paper";
        $("#form-paper-edit").validate({
            focusCleanup: true
        });
        // 当被退回后进行更新时显示退回记录
        $(function(){
            var pid = $("#p_id").val();
            var options = {
                url: prefix + "/bhxs/"+pid,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination:false,
                columns: [

                    {
                        field : 'create_time',
                        title : '批阅时间',
                        width: 200

                    } ,
                    {
                        field : 'uname',
                        title : '批阅人',
                        width: 100
                    },
                    {
                        field : 'concate',
                        title : '内容',
                        width: 500
                    },
                    {
                        field : 'state',
                        title : '审核状态',
                        width: 100
                    } ]
            };
            $.table.init(options);

            $('#bootstrap-table').on('load-success.bs.table', function (e, name, args) {
                console.log('Event Name:', name.rows);
                var a =$("#state").val();

                if(a != 1){
                    if(name.rows.length > 0){
                        $(".tdiv2").show();
                    }
                }

            });
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-paper-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                allowedFileExtensions: ["pdf"]
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        $("input[name='publicationTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        window.onload = function() {
            displayFileName('text_paper', 'contractFileName');
            displayFileName('word_paper', 'wordFileName');
        };
    </script>
</body>
</html>